package com.acg.service.impl;

import com.acg.entity.Favorite;
import com.acg.dao.FavoriteDao;
import com.acg.service.FavoriteService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import jakarta.annotation.Resource;
import java.util.*;
/**
 * 收藏表(Favorite)表服务实现类
 *
 * @author makejava
 * @since 2025-07-01 16:34:32
 */
@Service("favoriteService")
public class FavoriteServiceImpl implements FavoriteService {
    @Resource
    private FavoriteDao favoriteDao;

    /**
     * 通过ID查询单条数据
     *
     * @param favoriteId 主键
     * @return 实例对象
     */
    @Override
    public Favorite queryById(Integer favoriteId) {
        return this.favoriteDao.queryById(favoriteId);
    }

    /**
     * 分页查询
     *
     * @param favorite 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<Favorite> queryByPage(Favorite favorite, PageRequest pageRequest) {
        long total = this.favoriteDao.count(favorite);
        return new PageImpl<>(this.favoriteDao.queryAllByLimit(favorite, pageRequest), pageRequest, total);
    }
    /**
    获取所有的数据
    */
    @Override
    public List<Favorite> queryAll(){
        return  this.favoriteDao.queryAll();   
    }

    /**
     * 新增数据
     *
     * @param favorite 实例对象
     * @return 实例对象
     */
    @Override
    public Favorite insert(Favorite favorite) {
        this.favoriteDao.insert(favorite);
        return favorite;
    }

    /**
     * 修改数据
     *
     * @param favorite 实例对象
     * @return 实例对象
     */
    @Override
    public Favorite update(Favorite favorite) {
        this.favoriteDao.update(favorite);
        return this.queryById(favorite.getFavoriteId());
    }

    /**
     * 通过主键删除数据
     *
     * @param favoriteId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer favoriteId) {
        return this.favoriteDao.deleteById(favoriteId) > 0;
    }
}
